<template>
    <page-decorator>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户列表 </h5>
                        <div class="ibox-tools">
                            <button class="btn btn-primary btn-xs" v-on:click="refurbishModel()">
                            刷新
                            </button>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <el-list :stateManager="stateManager"></el-list>
                    </div>
                </div>
            </div>
        </div>

        <el-dialog :stateManager="stateManager"></el-dialog>
        <confirm-modal v-if="stateManager.deleteDialogVisible" text="你确定要删除此项内容吗？" title="删除确认"
                       v-on:cancel="stateManager.deleteDialogVisible= false"  v-on:ok="deleteModel"
        ></confirm-modal>
    </page-decorator>
</template>

<script>

    import dialog from './_dialog.vue';
    import table from './_table.vue';
    export default {
        components: {
            'el-dialog':dialog,
            'el-list': table,
        },
        data: function () {
            return {
//                departments: [{label: '综合部', value: 1}, {label: '技术部', value: 2}, {label: '行政部', value: 3}],
                stateManager: {
                    refreshList: true,
                    SeeDialogVisible: false,
                    SeeModelId: 0,
                    deleteDialogVisible: false,
                    deleteModelId: 0,
                    selectModelID:[],
                    userTags:[],
                },
                link:'',
                model: this.$modelDataSource({
                    url: 'api/WeChat/WeChatUser',
                    dataKey: 'model',
                    attributes: {
                        id: 0,
                    }
                })
            };
        },
        created: function () {
            this.$store.commit('setTitle', '用户管理');
            //getTags()
        },
        methods: {
            deleteModel: function () {
                this.stateManager.deleteDialogVisible = false;
                let self = this;
                self.model.id = this.stateManager.deleteModelId;
                self.model.destroy(function () {
                    self.model.reset();
                    self.stateManager.refreshList = true;
                    toastr.success('删除成功！');
                }, function () {
                    if (self.model.errors.permissions_errors) {
                        toastr.error(self.model.errors.permissions_errors);
                    }
                });
            },
            refurbishModel(){
                axios.get('/wechat/UserResult');
                this.stateManager.refreshList =true;
            },
            getTags(){
                let self = this;
                //   console.log(this.$store.state.on_line_weChat_id)
                axios.get('wechat/get-tag/'+this.$store.state.on_line_weChat_id).then(function (response) {
                    self.stateManager.userTags = response.data;
                }).catch(function (error) {
                    console.log(error);
                });
            }
        },
    }
</script>